package ch7;

import java.util.Arrays;
import java.util.Scanner;

public class Demo1 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] name = new String[5];
		String[] address = new String[5];
		String[] status = new String[5];
		double delivery[] = new double[5];
		double meals[] = new double[5];
		double total[] = new double[5];
		int menuNum[] = new int[5];
		int amount[] = new int[5];
		int time[] = new int[5];
		int count = 0;

		String menu[] = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };
		double price[] = { 38.0, 20.0, 10.0 };
		int admire[] = new int[3];
		String system[] = { "欢迎使用“吃货联盟订餐系统”\n*****************************************************", "1、我要订餐", "2、查看餐袋",
				"3、签收订单", "4、删除订单", "5、我要点赞", "6、退出系统", "*****************************************************" };
		while (true) {
			for (String c : system) {
				System.out.println(c);
			}
			System.out.print("请输入：");
			int sys = input.nextInt();
			switch (sys) {
			case 1:
				// if(count>=name.length)
				// {
				// name=Arrays.copyOf(name, name.length+3);
				// ...total,address...
				// }
				System.out.println("***我要订餐***");
				System.out.print("请输入订餐人姓名：");
				name[count] = input.next();
				System.out.println("序号\t\t\t菜名\t\t\t单价\t\t\t点赞数\t");
				for (int j = 0; j < menu.length; j++) {
					System.out.println((j + 1) + "\t\t\t" + menu[j] + "\t\t" + price[j] + "\t\t" + admire[j]);
				}
				System.out.print("请选择您要点的菜品编号：");
				menuNum[count] = input.nextInt();
				System.out.print("请选择您需要的份数：");
				amount[count] = input.nextInt();
				for (int j = 0;; j++) {
					System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐)：");
					time[count] = input.nextInt();
					if (time[count] >= 10 && time[count] <= 20)
						break;
					System.out.println("输入错误，重新输入");
				}
				System.out.print("送餐地址：");
				address[count] = input.next();
				System.out.println("订餐成功！");
				status[count] = "已预订";
				meals[count] = price[menuNum[count] - 1] * amount[count];
				if (meals[count] >= 50)
					delivery[count] = 0;
				else
					delivery[count] = 5;
				total[count] = meals[count] + delivery[count];
				System.out.println("您订的是：" + menu[menuNum[count] - 1] + amount[count] + "份");
				System.out.println("送餐时间：" + time[count] + "点");
				System.out.println("餐费：" + meals[count] + "元，送餐费：" + delivery[count] + "元，总计：" + total[count] + "元");
				count++;
				break;
			case 2:
				System.out.println("***查看餐袋***");
				if (count == 0) {
					System.out.println("未有订单信息");
				} else {
					System.out.println("序号\t订餐人\t餐品信息\t\t\t\t送餐时间\t\t送餐地址\t\t\t总金额\t\t定单状态");
					for (int j = 0; j < count; j++) {
						System.out.println(
								(j + 1) + "\t" + name[j] + "\t\t" + menu[menuNum[j] - 1] + amount[j] + "份\t\t\t"
										+ time[j] + "点\t\t\t" + address[j] + "\t\t" + total[j] + "元\t\t" + status[j]);
					}
				}
				break;
			case 3:
				System.out.println("***签收订单***");
				if (count == 0)
					System.out.println("未有订单信息");
				else if (count > 0) {
					while (true) {
						System.out.print("输入要签收订单的序号：");
						int num = input.nextInt();
						if (num > count) {
							System.out.println("输入错误，请重新输入");
						} else {
							if (status[num - 1].equals("已预订")) {
								status[num - 1] = "已完成";
								System.out.println("签收成功");
							} else if (status[num - 1].equals("已完成")) {
								System.out.println("该订单已完成签收");
							}
							break;
						}
					}
				}
				break;
			case 4:
				System.out.println("***删除订单***");
				if (count == 0)
					System.out.println("未有订单信息");
				while (count > 0) {
					System.out.print("请输入需要删除的订单序号：");
					int num2 = input.nextInt();
					if (num2 > count || num2 <= 0) {
						System.out.println("输入错误，请重新输入");
					} else {
						if (status[num2 - 1].equals("已完成")) {
							for (int i = num2 - 1; i < count; i++) {
								name[i] = name[i + 1];
								address[i] = address[i + 1];
								time[i] = time[i + 1];
								menuNum[i] = menuNum[i + 1];
								total[i] = total[i + 1];
								status[i] = status[i + 1];
							}
							System.out.println("订单删除成功");
							count--;
						} else if (status[num2 - 1].equals("已预订")) {
							System.out.println("该订单未完成签收，请签收后再操作");
						}
						break;
					}
				}
				break;
			case 5:
				System.out.println("***我要点赞***");
				if (count > 0) {
					for (int i = 0; i < count; i++) {
						if (status[i].equals("已完成")) {
							System.out.println("序号\t\t\t菜名\t\t\t单价\t\t\t点赞数\t");
							for (int j = 0; j < menu.length; j++) {
								System.out
										.println((j + 1) + "\t\t\t" + menu[j] + "\t\t" + price[j] + "\t\t" + admire[j]);
							}
							System.out.print("请选择您要点赞的菜品编号：");
							int num3 = input.nextInt();
							admire[num3 - 1]++;
							System.out.println("点赞完成");
						} else if (status[i].equals("已预订")) {
							System.out.println("请完成订单后再来点赞");
						}
						break;
					}
				} else
					System.out.println("未有订单信息，请完成订单后再来点赞");
				break;
			default:
				System.out.println("谢谢使用，欢迎下次光临");
				return;
			}
			System.out.print("输入0返回：");
			int a = input.nextInt();
			if (a == 0)
				continue;
			else {
				System.out.println("谢谢使用，欢迎下次光临");
				return;
			}
		}
	}
}